package com.cskaoyan.service.impl;

import com.cskaoyan.mapper.MarketGoodsProductMapper;
import com.cskaoyan.model.MarketGoodsProduct;
import com.cskaoyan.model.MarketGoodsProductExample;
import com.cskaoyan.service.GoodsProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Pudding
 * @Date 2024/6/13 21:54
 */
@Service
public class GoodsProductServiceImpl implements GoodsProductService {
    @Autowired
    MarketGoodsProductMapper goodsProductMapper;

    @Override
    public MarketGoodsProduct findById(Integer productId) {
        //1. 构造查询条件
        MarketGoodsProductExample example = new MarketGoodsProductExample();
        example.createCriteria().andDeletedEqualTo(false)
                .andIdEqualTo(productId);

        //2. 进行查询
        List<MarketGoodsProduct> products = goodsProductMapper.selectByExample(example);
        return products != null && products.size() == 1 ? products.get(0) : null;
    }
}
